<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue2过滤器</title>
</head>
<body>
  <div id="app">
    {{ sex | sexFilter }} - {{ price | priceFilter('$') }} --- {{ price | priceFilter('¥') }}
  </div>
</body>
<script src="../lib/vue.js"></script>
<script>

  // 全局过滤器
  Vue.filter('sexFilter', (val) => {
    return val === 1 ? '男' : '女'
  })

  new Vue({
    data: {
      sex: 1, // 1 男 0 女
      price: 100
    },
    // 局部过滤器
    filters: {
      priceFilter: (val, type) => {
        console.log(val, type) // 100 ¥
        return type + val
      }
    }
  }).$mount('#app')
</script>
</html>